#ifndef NSSHARE_UTILS_EVENT_DELEGATE_H_
#define NSSHARE_UTILS_EVENT_DELEGATE_H_

#include "event_handler.h"

namespace nsshare
{
namespace utils
{

template<typename A>
class EventDelegate
{
public:
    typedef EventHandler<A> H;

    EventDelegate()
        : h_(0)
    {
    }

    EventDelegate & operator=(H * h)
    {
        h_ = h;
        return *this;
    }

    void operator()(base::BaseObject * sender, A arg)
    {
        if(h_)
            h_->OnEvent(sender, arg);
    }

    bool operator!=(void * ptr)
    {
        return h_ != ptr;
    }

    bool operator==(void * ptr)
    {
        return h_ == ptr;
    }

private:
     H * h_;
};

}
}

#endif